import time

from selenium.webdriver.common.by import By

from common.base import Base
from common.functions import open_browser


class SubmitPage(Base):
    # 申通快递
    def sto_express(self):
        self.click((By.XPATH, "//input[@name='shipping' and @value='5']"))

    # 邮局平邮
    def surface_mail(self):
        self.click((By.XPATH, "//input[@name='shipping' and @value='6']"))

    # 余额支付
    def remaining_sum(self):
        self.click((By.XPATH, "//*[@name='pack' and @value='1']"))

    # 银行汇款
    def remittance(self):
        self.click((By.XPATH, "//*[@name='payment' and @value='2']"))

    # 不要包装
    def no_package(self):
        self.click((By.XPATH, "//*[@name='pack' and @value='0']"))

    # 精美包装
    def packing(self):
        self.click((By.XPATH, "//*[@name='pack' and @value='1']"))

    # 不要贺卡
    def no_greeting_card(self):
        self.click((By.XPATH, "//*[@name='card' and @value='0']"))

    # 祝福贺卡
    def greeting_card(self):
        self.click((By.XPATH, "//*[@name='card' and @value='1']"))

    # 积分栏
    def integral_column(self, value):
        self.send_keys((By.ID, "ECS_INTEGRAL"), value)

    # 红包输入框
    def red_envelope_number(self, value):
        self.send_keys((By.NAME, "bonus_sn"), value)

    # 验证红包
    def verify_red_envelopes(self):
        self.click((By.CLASS_NAME, "bnt_blue_1"))
        alter = self.driver.switch_to.alert
        time.sleep(3)
        alter.accept()

    # 是否开发票
    def invoice(self):
        self.click((By.ID, "ECS_NEEDINV"))

    # 发票抬头
    def invoice_header(self, value):
        self.send_keys((By.ID, 'ECS_INVPAYEE'), value)

    # 订单附言
    def postscript(self, content):
        self.send_keys((By.ID, "postscript"), content)

    # 等待所有商品
    def wait_for(self):
        self.click((By.XPATH, "//*[@name='how_oos' and @value='0']"))

    # 取消订单
    def cancel(self):
        self.click((By.XPATH, "//input[@name='how_oos'and @value='1']"))

    # 与店家协商
    def shop_negotiation(self):
        self.click((By.XPATH, "//input[@name='how_oos'and @value='2']"))

    def place_order(self):
        self.click((By.XPATH, '//*[@id="theForm"]/div[15]/div[2]/input[1]'))


if __name__ == '__main__':
    browser = open_browser()
    submitpage = SubmitPage(browser)
    submitpage.get("http://139.129.26.163/flow.php?step=checkout")
